﻿using System;
using System.Data;
using System.Text;
using System.Data.OracleClient;
using ChinaSoft.DBUtility;//Please add references
namespace ChinaSoft.DAL
{
	/// <summary>
	/// 数据访问类:DAL_T_PET_OPINION
	/// </summary>
	public partial class DAL_T_PET_OPINION
	{
		public DAL_T_PET_OPINION()
		{}
		#region  Method

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(string PET_OPINION_ID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from T_PET_OPINION");
			strSql.Append(" where PET_OPINION_ID=:PET_OPINION_ID ");
			OracleParameter[] parameters = {
					new OracleParameter(":PET_OPINION_ID", OracleType.VarChar,40)			};
			parameters[0].Value = PET_OPINION_ID;

			return DbHelperOra.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(ChinaSoft.Model.Model_T_PET_OPINION model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into T_PET_OPINION(");
			strSql.Append("PET_OPINION_ID,COM_OPINION,DEP_OPINION,NOTE,PETDEP_OPINION,PET_ID,POLICE_OPINION,REG_ORG_ID,SHIRONG_OPINION,STREET_OPINION,LEADER_OPINION,CREATE_TIME,CREATOR_ID,UPDATE_TIME,UPDATOR_ID)");
			strSql.Append(" values (");
			strSql.Append(":PET_OPINION_ID,:COM_OPINION,:DEP_OPINION,:NOTE,:PETDEP_OPINION,:PET_ID,:POLICE_OPINION,:REG_ORG_ID,:SHIRONG_OPINION,:STREET_OPINION,:LEADER_OPINION,:CREATE_TIME,:CREATOR_ID,:UPDATE_TIME,:UPDATOR_ID)");
			OracleParameter[] parameters = {
					new OracleParameter(":PET_OPINION_ID", OracleType.VarChar,40),
					new OracleParameter(":COM_OPINION", OracleType.NVarChar),
					new OracleParameter(":DEP_OPINION", OracleType.NVarChar),
					new OracleParameter(":NOTE", OracleType.NVarChar),
					new OracleParameter(":PETDEP_OPINION", OracleType.NVarChar),
					new OracleParameter(":PET_ID", OracleType.VarChar,40),
					new OracleParameter(":POLICE_OPINION", OracleType.NVarChar),
					new OracleParameter(":REG_ORG_ID", OracleType.VarChar,40),
					new OracleParameter(":SHIRONG_OPINION", OracleType.NVarChar),
					new OracleParameter(":STREET_OPINION", OracleType.NVarChar),
					new OracleParameter(":LEADER_OPINION", OracleType.NVarChar),
					new OracleParameter(":CREATE_TIME", OracleType.DateTime),
					new OracleParameter(":CREATOR_ID", OracleType.VarChar,40),
					new OracleParameter(":UPDATE_TIME", OracleType.DateTime),
					new OracleParameter(":UPDATOR_ID", OracleType.VarChar,40)};
			parameters[0].Value = model.PET_OPINION_ID;
			parameters[1].Value = model.COM_OPINION;
			parameters[2].Value = model.DEP_OPINION;
			parameters[3].Value = model.NOTE;
			parameters[4].Value = model.PETDEP_OPINION;
			parameters[5].Value = model.PET_ID;
			parameters[6].Value = model.POLICE_OPINION;
			parameters[7].Value = model.REG_ORG_ID;
			parameters[8].Value = model.SHIRONG_OPINION;
			parameters[9].Value = model.STREET_OPINION;
			parameters[10].Value = model.LEADER_OPINION;
			parameters[11].Value = model.CREATE_TIME;
			parameters[12].Value = model.CREATOR_ID;
			parameters[13].Value = model.UPDATE_TIME;
			parameters[14].Value = model.UPDATOR_ID;

			int rows=DbHelperOra.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(ChinaSoft.Model.Model_T_PET_OPINION model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update T_PET_OPINION set ");
			strSql.Append("COM_OPINION=:COM_OPINION,");
			strSql.Append("DEP_OPINION=:DEP_OPINION,");
			strSql.Append("NOTE=:NOTE,");
			strSql.Append("PETDEP_OPINION=:PETDEP_OPINION,");
			strSql.Append("PET_ID=:PET_ID,");
			strSql.Append("POLICE_OPINION=:POLICE_OPINION,");
			strSql.Append("REG_ORG_ID=:REG_ORG_ID,");
			strSql.Append("SHIRONG_OPINION=:SHIRONG_OPINION,");
			strSql.Append("STREET_OPINION=:STREET_OPINION,");
			strSql.Append("LEADER_OPINION=:LEADER_OPINION,");
			strSql.Append("CREATE_TIME=:CREATE_TIME,");
			strSql.Append("CREATOR_ID=:CREATOR_ID,");
			strSql.Append("UPDATE_TIME=:UPDATE_TIME,");
			strSql.Append("UPDATOR_ID=:UPDATOR_ID");
			strSql.Append(" where PET_OPINION_ID=:PET_OPINION_ID ");
			OracleParameter[] parameters = {
					new OracleParameter(":COM_OPINION", OracleType.NVarChar),
					new OracleParameter(":DEP_OPINION", OracleType.NVarChar),
					new OracleParameter(":NOTE", OracleType.NVarChar),
					new OracleParameter(":PETDEP_OPINION", OracleType.NVarChar),
					new OracleParameter(":PET_ID", OracleType.VarChar,40),
					new OracleParameter(":POLICE_OPINION", OracleType.NVarChar),
					new OracleParameter(":REG_ORG_ID", OracleType.VarChar,40),
					new OracleParameter(":SHIRONG_OPINION", OracleType.NVarChar),
					new OracleParameter(":STREET_OPINION", OracleType.NVarChar),
					new OracleParameter(":LEADER_OPINION", OracleType.NVarChar),
					new OracleParameter(":CREATE_TIME", OracleType.DateTime),
					new OracleParameter(":CREATOR_ID", OracleType.VarChar,40),
					new OracleParameter(":UPDATE_TIME", OracleType.DateTime),
					new OracleParameter(":UPDATOR_ID", OracleType.VarChar,40),
					new OracleParameter(":PET_OPINION_ID", OracleType.VarChar,40)};
			parameters[0].Value = model.COM_OPINION;
			parameters[1].Value = model.DEP_OPINION;
			parameters[2].Value = model.NOTE;
			parameters[3].Value = model.PETDEP_OPINION;
			parameters[4].Value = model.PET_ID;
			parameters[5].Value = model.POLICE_OPINION;
			parameters[6].Value = model.REG_ORG_ID;
			parameters[7].Value = model.SHIRONG_OPINION;
			parameters[8].Value = model.STREET_OPINION;
			parameters[9].Value = model.LEADER_OPINION;
			parameters[10].Value = model.CREATE_TIME;
			parameters[11].Value = model.CREATOR_ID;
			parameters[12].Value = model.UPDATE_TIME;
			parameters[13].Value = model.UPDATOR_ID;
			parameters[14].Value = model.PET_OPINION_ID;

			int rows=DbHelperOra.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(string PET_OPINION_ID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from T_PET_OPINION ");
			strSql.Append(" where PET_OPINION_ID=:PET_OPINION_ID ");
			OracleParameter[] parameters = {
					new OracleParameter(":PET_OPINION_ID", OracleType.VarChar,40)			};
			parameters[0].Value = PET_OPINION_ID;

			int rows=DbHelperOra.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string PET_OPINION_IDlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from T_PET_OPINION ");
			strSql.Append(" where PET_OPINION_ID in ("+PET_OPINION_IDlist + ")  ");
			int rows=DbHelperOra.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public ChinaSoft.Model.Model_T_PET_OPINION GetModel(string PET_OPINION_ID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select PET_OPINION_ID,COM_OPINION,DEP_OPINION,NOTE,PETDEP_OPINION,PET_ID,POLICE_OPINION,REG_ORG_ID,SHIRONG_OPINION,STREET_OPINION,LEADER_OPINION,CREATE_TIME,CREATOR_ID,UPDATE_TIME,UPDATOR_ID from T_PET_OPINION ");
			strSql.Append(" where PET_OPINION_ID=:PET_OPINION_ID ");
			OracleParameter[] parameters = {
					new OracleParameter(":PET_OPINION_ID", OracleType.VarChar,40)			};
			parameters[0].Value = PET_OPINION_ID;

			ChinaSoft.Model.Model_T_PET_OPINION model=new ChinaSoft.Model.Model_T_PET_OPINION();
			DataSet ds=DbHelperOra.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["PET_OPINION_ID"]!=null && ds.Tables[0].Rows[0]["PET_OPINION_ID"].ToString()!="")
				{
					model.PET_OPINION_ID=ds.Tables[0].Rows[0]["PET_OPINION_ID"].ToString();
				}
				if(ds.Tables[0].Rows[0]["COM_OPINION"]!=null && ds.Tables[0].Rows[0]["COM_OPINION"].ToString()!="")
				{
					model.COM_OPINION=ds.Tables[0].Rows[0]["COM_OPINION"].ToString();
				}
				if(ds.Tables[0].Rows[0]["DEP_OPINION"]!=null && ds.Tables[0].Rows[0]["DEP_OPINION"].ToString()!="")
				{
					model.DEP_OPINION=ds.Tables[0].Rows[0]["DEP_OPINION"].ToString();
				}
				if(ds.Tables[0].Rows[0]["NOTE"]!=null && ds.Tables[0].Rows[0]["NOTE"].ToString()!="")
				{
					model.NOTE=ds.Tables[0].Rows[0]["NOTE"].ToString();
				}
				if(ds.Tables[0].Rows[0]["PETDEP_OPINION"]!=null && ds.Tables[0].Rows[0]["PETDEP_OPINION"].ToString()!="")
				{
					model.PETDEP_OPINION=ds.Tables[0].Rows[0]["PETDEP_OPINION"].ToString();
				}
				if(ds.Tables[0].Rows[0]["PET_ID"]!=null && ds.Tables[0].Rows[0]["PET_ID"].ToString()!="")
				{
					model.PET_ID=ds.Tables[0].Rows[0]["PET_ID"].ToString();
				}
				if(ds.Tables[0].Rows[0]["POLICE_OPINION"]!=null && ds.Tables[0].Rows[0]["POLICE_OPINION"].ToString()!="")
				{
					model.POLICE_OPINION=ds.Tables[0].Rows[0]["POLICE_OPINION"].ToString();
				}
				if(ds.Tables[0].Rows[0]["REG_ORG_ID"]!=null && ds.Tables[0].Rows[0]["REG_ORG_ID"].ToString()!="")
				{
					model.REG_ORG_ID=ds.Tables[0].Rows[0]["REG_ORG_ID"].ToString();
				}
				if(ds.Tables[0].Rows[0]["SHIRONG_OPINION"]!=null && ds.Tables[0].Rows[0]["SHIRONG_OPINION"].ToString()!="")
				{
					model.SHIRONG_OPINION=ds.Tables[0].Rows[0]["SHIRONG_OPINION"].ToString();
				}
				if(ds.Tables[0].Rows[0]["STREET_OPINION"]!=null && ds.Tables[0].Rows[0]["STREET_OPINION"].ToString()!="")
				{
					model.STREET_OPINION=ds.Tables[0].Rows[0]["STREET_OPINION"].ToString();
				}
				if(ds.Tables[0].Rows[0]["LEADER_OPINION"]!=null && ds.Tables[0].Rows[0]["LEADER_OPINION"].ToString()!="")
				{
					model.LEADER_OPINION=ds.Tables[0].Rows[0]["LEADER_OPINION"].ToString();
				}
				if(ds.Tables[0].Rows[0]["CREATE_TIME"]!=null && ds.Tables[0].Rows[0]["CREATE_TIME"].ToString()!="")
				{
					model.CREATE_TIME=DateTime.Parse(ds.Tables[0].Rows[0]["CREATE_TIME"].ToString());
				}
				if(ds.Tables[0].Rows[0]["CREATOR_ID"]!=null && ds.Tables[0].Rows[0]["CREATOR_ID"].ToString()!="")
				{
					model.CREATOR_ID=ds.Tables[0].Rows[0]["CREATOR_ID"].ToString();
				}
				if(ds.Tables[0].Rows[0]["UPDATE_TIME"]!=null && ds.Tables[0].Rows[0]["UPDATE_TIME"].ToString()!="")
				{
					model.UPDATE_TIME=DateTime.Parse(ds.Tables[0].Rows[0]["UPDATE_TIME"].ToString());
				}
				if(ds.Tables[0].Rows[0]["UPDATOR_ID"]!=null && ds.Tables[0].Rows[0]["UPDATOR_ID"].ToString()!="")
				{
					model.UPDATOR_ID=ds.Tables[0].Rows[0]["UPDATOR_ID"].ToString();
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select PET_OPINION_ID,COM_OPINION,DEP_OPINION,NOTE,PETDEP_OPINION,PET_ID,POLICE_OPINION,REG_ORG_ID,SHIRONG_OPINION,STREET_OPINION,LEADER_OPINION,CREATE_TIME,CREATOR_ID,UPDATE_TIME,UPDATOR_ID ");
			strSql.Append(" FROM T_PET_OPINION ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperOra.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM T_PET_OPINION ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.PET_OPINION_ID desc");
			}
			strSql.Append(")AS Row, T.*  from T_PET_OPINION T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperOra.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			OracleParameter[] parameters = {
					new OracleParameter(":tblName", OracleType.VarChar, 255),
					new OracleParameter(":fldName", OracleType.VarChar, 255),
					new OracleParameter(":PageSize", OracleType.Number),
					new OracleParameter(":PageIndex", OracleType.Number),
					new OracleParameter(":IsReCount", OracleType.Clob),
					new OracleParameter(":OrderType", OracleType.Clob),
					new OracleParameter(":strWhere", OracleType.VarChar,1000),
					};
			parameters[0].Value = "T_PET_OPINION";
			parameters[1].Value = "PET_OPINION_ID";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperOra.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  Method
	}
}

